package com.dgshanger.sanhxiaofeisc.ui.person.purse

import android.annotation.SuppressLint
import android.content.Intent
import com.dgshanger.sanhxiaofeisc.R
import com.dgshanger.sanhxiaofeisc.common.Constants
import com.dgshanger.sanhxiaofeisc.mvp.contract.WithdrawContract
import com.dgshanger.sanhxiaofeisc.mvp.presenter.WithdrawPresenter
import com.dgshanger.sanhxiaofeisc.ui.person.setting.EditPayPasswordActivity
import com.xx.baseuilibrary.mvp.BaseMvpActivity
import com.xxl.sodmall.dialog.WalletPayDialogWrapper
import kotlinx.android.synthetic.main.activity_pay_model_setting.*
import kotlinx.android.synthetic.main.activity_withdraw.*


/**
 * WithdrawActivity
 * 沉迷学习不能自拔
 * Describe：提现页面
 * Created by 雷小星🍀 on 2018/4/18 14:49.
 */
class WithdrawActivity : BaseMvpActivity<WithdrawContract.Model, WithdrawContract.View, WithdrawPresenter>(), WithdrawContract.View {

    private var mPayPwd : String = ""

    override fun getAccount(): String = et_account.text.toString()

    override fun getMoney(): String = et_withdraw_money.text.toString()

    override fun getPayPwd(): String = mPayPwd

    override fun createPresenter(): WithdrawPresenter = WithdrawPresenter()

    override fun getActivityLayoutId(): Int = R.layout.activity_withdraw

    @SuppressLint("SetTextI18n")
    override fun initData() {
        et_withdraw_money.setHint("零钱剩余${Constants.getUserEntity().wallet_money}")
    }

    override fun initEvent() {
        btn_sure.setOnClickListener {
            getPresenter().checkPayPwd()
        }
    }

    override fun onSettingPayPwd() {
        val intent = Intent(mContext, EditPayPasswordActivity::class.java)
        startActivity(intent)
    }

    override fun showPayPwdDialog() {
        val walletPayDialogWapper = WalletPayDialogWrapper(mContext, money)
        walletPayDialogWapper.setOnPasswordFinishListener(object : WalletPayDialogWrapper.OnPasswordFinishListener{
            override fun onPasswordFinishListener(password: String) {
                mPayPwd=password
                getPresenter().withdraw()
                walletPayDialogWapper.dismissDialog()
            }
        })
        walletPayDialogWapper.showDialog()
    }
}